package wch;

import static org.junit.Assert.assertFalse;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that DaRumble moves away from a robot if it hits one, specified by it strategy.
 * 
 * @author Christopher Wilson
 */
public class TestDaRumbleRumbles extends RobotTestBed {
  /** True if the robot moved if it hit another robot. */
  boolean movedOnHitRobot = true;

  /**
   * Specifies that Crazy and DaRumble are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,wch.DaRumble";
  }

  /**
   * This test runs for 20 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 20;
  }

  /**
   * After each turn, check to see if we hit another robot. If so, set the corresponding flag.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot DaRumble
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();
    double newPosX, newPosY;
    if (robot.getState().isHitRobot()) {
      newPosX = robot.getX();
      newPosY = robot.getY();
      if (xPos == newPosX && yPos == newPosY) {
        movedOnHitRobot = false;
      }
    }

  }

  /**
   * After the battle, check to see that we've visited the corners.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertFalse("Must move on enemy impact", movedOnHitRobot);

  }
}
